package com.zhiyou100.day1029springbooot.controller;

import com.zhiyou100.day1029springbooot.mapper.ITeacherMapper;
import com.zhiyou100.day1029springbooot.pojo.Teacher;
import com.zhiyou100.day1029springbooot.service.ITeacherService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
/**/
@Controller
/*二级目录*/
@RequestMapping("teacher")
public class TeacherController {
    /*引入teacherService*/
    @Resource
    private ITeacherService teacherService;
    /*查询*/
    @RequestMapping("get")
    public String getTeacher(Model model){
        model.addAttribute("teachers",teacherService.queryAll());
        return "show";
    }
    /*跳转添加界面*/
    @RequestMapping("add")
    public String addTeacher(){

        return "add";
    }
    /*添加方法*/
    @RequestMapping("insert")
    public String insertTeacher(Teacher teacher){
        teacherService.add(teacher);
        return "redirect:get";
    }
    /*删除*/
    @RequestMapping("delete")
    public String delete(Integer id){
        teacherService.deleteById(id);
        return "redirect:get";
    }
    /*跳转修改界面,并查询当前id所属于的值*/
    @RequestMapping("find")
    public String find(Integer id,Model model){
       model.addAttribute("teacher",teacherService.findById(id));
        return "update";
    }
    /*修改*/
    @RequestMapping("update")
    public String update(Teacher teacher){
        teacherService.update(teacher);
        return "redirect:get";
    }
}
